import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { ObjCreate } from "../../common/ObjCreate";
import { PetExploreConfigInfo } from "../../../resource/info/PetExploreConfigInfo";
import { PetExploreConfig } from "../../../resource/PetExploreConfig";
import { Language } from "../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { DataEvent } from "../../../events/DataEvent";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class PetExploreRoadblock
    
    export  class PetExploreRoadblock /* flash.display.Sprite */
    {
        constructor(arg1: Object /* flash.display.Sprite */)
        {
            
            this._parentSp = arg1;
            this.init();
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onThisClickHandler);
            Dispatcher.addEventListener(EventName.PetExploreSelectRb, this.onPetExploreSelectRbHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._pointBtn = ObjCreate.createGButton("", 0, 0, 14, 14, this, "GraySmallButton");
            return;
        }

        public get exploreConfig(): PetExploreConfigInfo
        {
            return this._exploreConfig;
        }

        public set exploreConfig(arg1: PetExploreConfigInfo)
        {
            this._exploreConfig = arg1;
            if (arg1) 
            {
                this._name = arg1.name;
                this._dropName = arg1.dropItemName;
                this._level = arg1.level;
                this._isAreaFirst = PetExploreConfig.instance.isAreaFirstRoadblock(arg1);
                this.updateIsCanExplore();
            }
            return;
        }

        public get status(): int
        {
            return this._status;
        }

        public set status(arg1: int)
        {
            var loc1="";
            this._status = arg1;
            if (this._status != 0) 
            {
                if (this._status != 1) 
                {
                    if (this._status != 2) 
                    {
                        if (this._status == 3) 
                        {
                            this._preExploreConfig = PetExploreConfig.instance.getExploreConfigByLevel((this._exploreConfig.level - 1));
                            if (this._preExploreConfig) 
                            {
                                this._preName = this._preExploreConfig.name;
                                loc1 = Language.getStringByParam(54504, this._dropName, this._preName);
                            }
                            else 
                            {
                                loc1 = "";
                            }
                            this._statusStr = HTMLUtil.addColor(Language.getString(54505), "#f0ea3f") + Language.getString(54628);
                            if (this._isAreaFirst) 
                            {
                                this._pointBtn.styleName = "GreenBigButton";
                                this._pointBtn.setSize(20, 20);
                            }
                            else 
                            {
                                this._pointBtn.styleName = "GreenSmallButton";
                                this._pointBtn.setSize(14, 14);
                            }
                        }
                    }
                    else 
                    {
                        this._preExploreConfig = PetExploreConfig.instance.getExploreConfigByLevel((this._exploreConfig.level - 1));
                        if (this._preExploreConfig) 
                        {
                            this._preName = this._preExploreConfig.name;
                            loc1 = Language.getStringByParam(54504, this._dropName, this._preName);
                        }
                        else 
                        {
                            loc1 = "";
                        }
                        this._statusStr = HTMLUtil.addColor(Language.getString(54505), "#f0ea3f");
                        if (this._isAreaFirst) 
                        {
                            this._pointBtn.styleName = "GrayBigButton";
                            this._pointBtn.setSize(20, 20);
                        }
                        else 
                        {
                            this._pointBtn.styleName = "GraySmallButton";
                            this._pointBtn.setSize(14, 14);
                        }
                    }
                }
                else 
                {
                    this._statusStr = HTMLUtil.addColor(Language.getString(54503), "#ff0000");
                    loc1 = Language.getString(54542) + this._dropName;
                    if (this._isAreaFirst) 
                    {
                        this._pointBtn.styleName = "GreenBigButton";
                        this._pointBtn.setSize(20, 20);
                    }
                    else 
                    {
                        this._pointBtn.styleName = "GreenSmallButton";
                        this._pointBtn.setSize(14, 14);
                    }
                }
            }
            else 
            {
                this._statusStr = HTMLUtil.addColor(Language.getString(54502), "#ff0000");
                loc1 = Language.getString(54542) + this._dropName;
                if (this._isAreaFirst) 
                {
                    this._pointBtn.styleName = "YellowBigButton";
                    this._pointBtn.setSize(20, 20);
                }
                else 
                {
                    this._pointBtn.styleName = "YellowSmallButton";
                    this._pointBtn.setSize(14, 14);
                }
                this.selected = false;
            }
            this._tip = Language.getStringByParam(54506, this._name, this._statusStr, loc1);
            this._pointBtn.toolTipData = this._tip;
            return;
        }

        public updateIsCanExplore(): void
        {
            this._isCanExplore = this.getIsCanExplore();
            if (this._isCanExplore && (this._isAreaFirst == true && this._exploreConfig.level == 1 || this._isAreaFirst == false || this._isOnlyCanExplore)) 
            {
                Cache.instance.petExplore.selectedConfigInfo = this._exploreConfig;
                this.selected = this._isCanExplore;
            }
            else 
            {
                this.selected = false;
            }
            return;
        }

        /* internal  */onThisClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=false;
            var loc3=0;
            if (!Cache.instance.petExplore.isCanExploreToday()) 
            {
                MsgManager.showRollTipsMsg(Language.getString(54507));
                return;
            }
            var loc2=Cache.instance.petExplore.petExploreInfo;
            if (this._exploreConfig.level <= loc2.maxLevel) 
            {
                if (loc2.currentLevel != 0) 
                {
                    if (loc2.currentLevel == this._exploreConfig.level) 
                    {
                        loc1 = true;
                    }
                }
                else if (this._isAreaFirst) 
                {
                    if ((loc3 = Cache.instance.petExplore.getExploreAreaIndex()) >= this._exploreConfig.area && this._exploreConfig.area > 1) 
                    {
                        Cache.instance.petExplore.selectedConfigInfo = this._exploreConfig;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreSkipWindowOpen));
                    }
                    loc1 = true;
                }
            }
            if (loc1) 
            {
                Cache.instance.petExplore.selectedConfigInfo = this._exploreConfig;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreSelectRb, this._exploreConfig.level));
            }
            this.selected = loc1;
            return;
        }

        public getIsCanExplore(): Boolean
        {
            var loc1=false;
            var loc2=Cache.instance.petExplore.petExploreInfo;
            this._isOnlyCanExplore = false;
            if (loc2 && Cache.instance.petExplore.isCanExploreToday()) 
            {
                if (this._exploreConfig.level <= loc2.maxLevel) 
                {
                    if (loc2.currentLevel != 0) 
                    {
                        if (loc2.currentLevel == this._exploreConfig.level) 
                        {
                            loc1 = true;
                            this._isOnlyCanExplore = true;
                        }
                    }
                    else if (this._isAreaFirst) 
                    {
                        loc1 = true;
                    }
                }
            }
            return loc1;
        }

        public get selected(): Boolean
        {
            return this._selected;
        }

        public set selected(arg1: Boolean)
        {
            var loc1=null;
            var loc2=null;
            this._selected = arg1;
            if (arg1) 
            {
                if (this._effectPlayer == null) 
                {
                    this._effectPlayer = new SWFPlayer();
                }
                this._effectPlayer.load("petExploreRBSelect.swf", ModelType.NormalSwf, null);
                loc1 = this.localToGlobal(new Object /* flash.geom.Point */(this._pointBtn.width / 2, -20));
                loc2 = this._parentSp.globalToLocal(loc1);
                this._effectPlayer.move(loc2.x, loc2.y);
                this._parentSp.addChild(this._effectPlayer);
                Cache.instance.petExplore.selectedConfigInfo = this._exploreConfig;
            }
            else 
            {
                DisplayUtil.removeMe(this._effectPlayer);
            }
            return;
        }

        /* internal  */onPetExploreSelectRbHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (this._exploreConfig.level == loc1) 
            {
                this.selected = true;
            }
            else 
            {
                this.selected = false;
            }
            return;
        }

        /* internal */ /* var */_pointBtn: GButton;

        /* internal */ /* var */_effectPlayer: SWFPlayer;

        /* internal */ /* var */_preExploreConfig: PetExploreConfigInfo;

        /* internal */ /* var */_exploreConfig: PetExploreConfigInfo;

        /* internal */ /* var */_preName: string;

        /* internal */ /* var */_name: string;

        /* internal */ /* var */_status: int;

        /* internal */ /* var */_statusStr: string="";

        /* internal */ /* var */_tip: string="";

        /* internal */ /* var */_dropName: string;

        /* internal */ /* var */_level: int;

        /* internal */ /* var */_selected: Boolean;

        /* internal */ /* var */_isAreaFirst: Boolean;

        /* internal */ /* var */_isCanExplore: Boolean;

        /* internal */ /* var */_isOnlyCanExplore: Boolean;

        /* internal */ /* var */_parentSp: Object /* flash.display.Sprite */;
    }
